#ifndef _LXP_SPLITER_H_
#define _LXP_SPLITER_H_

#include <string>
#include <fstream>

class ISpliter {
	public:
		virtual bool hasNextWord() = 0;
		virtual std::string nextWord() = 0;
		virtual void open(std::string filename) = 0;
		virtual void close() = 0;
};

class SimpleSpliter : public ISpliter{
	public:
		SimpleSpliter(){};


		void open(std::string filename);
		void close();

		bool hasNextWord();
		std::string nextWord();

		~SimpleSpliter() {
			closeFile();
		}

	private:
		SimpleSpliter(const SimpleSpliter&);
		SimpleSpliter& operator=(const SimpleSpliter&);
	private:
		void closeFile() {
			if(input.is_open())
				input.close();
		}

		bool is_open() {
			return input.is_open();
		}

		void openFile() {
			input.open(_filename.c_str());
		}
	protected:
		std::ifstream input;
		std::string _filename;
		std::string word;
};

class CLangSpliter : public SimpleSpliter {
	enum state_t{START, VAR, OPRAND, DIGIT};
	public:
		CLangSpliter() : state(START), prev_char(0) {}
		bool hasNextWord();
	private:
		state_t state;
		char prev_char;
};
#endif
